<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$return['member']=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','credit3','credit4','credit6','mobile','avatar','nickname'));
    $return['sale_red']=$this->pdo_getall('maxlog',array('type'=>0,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
    foreach($return['sale_red'] as &$sv){
        $sv['member']=cfc('core')->member_show($sv['mid']);
        $sv['createtime']=date('Y-m-d H:i',$sv['createtime']);
    }
    $return['red']=$_SESSION['member'];
    $return['red']['log']=$this->pdo_get('maxlog',array('status'=>0,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
    $credittype=$this->pdo_getcolumn('maxlog',array('type'=>0,'uniacid'=>$_SESSION['uniacid']),'credittype');
    $return['red']['typetitle']=$this->prizeType[$credittype];
    $return['red']['allfee']=$this->pdo_getsum('maxlog',array('type'=>0,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'fee');
    $return['red']['red_mp3']=$return['pluginset']['red_mp3'];
    if($return['red']['log']['id']){
        $return['showredpage']=true;
        $this->pdo_update('maxlog',array('status'=>1),array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
    }
	$sharelink='jy_manghe/index//fromuser='.$_SESSION['uid'];
	$return['sharedata']=array(
			'title'=>$this->setting['share_title']?:'盲盒商城-在线盲盒',
			'desc'=>$this->setting['share_desc']?:'盲盒商城，参与盲盒！',
			'link'=>custom_url($sharelink,true),
			'imgUrl'=>ATTACHMENT_URL.$return['pluginset']['logo']
	);
	set_html('title','盲盒商城');
	exi($return);
}
if($_RQ['op']=='getlist'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'plugin_name'=>'jy_manghe','merchid'=>0);
	if($_RQ['keyword']){
		$params['title like']='%;'.$_RQ['keyword'].';%';
	}
    $orderby='createtime desc';
	$total='';
	$list=pdo_getslice('jy_weishop_game',$params,array($pindex,$psize),$total,'','','id desc');
	if($list){
		$day=date('Y/m/d');
		foreach($list as &$item){
			$openlog=$this->model('model')->upopenlog($item);
			$item['pluginset']=json_decode($item['pluginset'],true);
			if($item['pluginset']['opentime']){
                $opentime=strtotime($item['pluginset']['opentime']);
                if($opentime>time()){
                    $item['status']=0;
                }
            }
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			$item['salenum']=pdo_count('jy_manghe_feelog',array('uniacid'=>$_SESSION['uniacid'],'gameid'=>$item['id']),'id');
			$item['statustitle']=$this->goods_status[$item['status']];
			if($item['status']==1){
				$rest_time=$openlog['opentime']-TIMESTAMP;
				if($rest_time>0){
					$item['rest_time']=model('jy_weishop/model')->date($rest_time);
				}
			}
			$pindex = max(1, 0);
			$psize = 4;
			$members=pdo_getslice('jy_manghe_feelog',array('uniacid'=>$_SESSION['uniacid'],'gameid'=>$item['id']),array($pindex,$psize),$total,array('mid'),'','id desc');
			foreach($members as &$mv){
				$memberinfo=pdo_get('core_members',array('id'=>$mv['mid']),array('nickname','avatar'));
				$mv['nickname']=$memberinfo['nickname'];
				$mv['avatar']=$memberinfo['avatar'];
			}
			$item['members']=$members;
		}
	}
	$return['list']=$list;
	exi($return);
}
?>